{"ast":null,"code":"var _jsxFileName = \"/data/messenger.client/src/components/UploadFiles/index.tsx\",\n  _s = $RefreshSig$();\nimport React from 'react';\nimport { Modal, Upload } from 'antd';\nimport './UploadFiles.scss';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\nimport { Fragment as _Fragment } from \"react/jsx-dev-runtime\";\nconst getBase64 = file => new Promise((resolve, reject) => {\n  const reader = new FileReader();\n  reader.readAsDataURL(file);\n  reader.onload = () => resolve(reader.result);\n  reader.onerror = error => reject(error);\n});\nconst UploadFiles = _ref => {\n  _s();\n  let {\n    uploaded\n  } = _ref;\n  const [previewOpen, setPreviewOpen] = React.useState(false);\n  const [previewImage, setPreviewImage] = React.useState('');\n  const [previewTitle, setPreviewTitle] = React.useState('');\n  const [fileList, setFileList] = React.useState();\n  React.useEffect(() => {\n    let tempFileList = {};\n    if (uploaded.items.length > 0) {\n      uploaded.items.map((item, index) => {\n        var _item$id;\n        tempFileList[index] = {\n          uid: ((_item$id = item.id) === null || _item$id === void 0 ? void 0 : _item$id.toString()) || '0',\n          status: \"done\",\n          url: item.link,\n          name: (process.env.REACT_APP_BACKEND_URL + '/' + item.link).split('/')[7]\n        };\n        setFileList({\n          ...fileList,\n          ...tempFileList\n        });\n      });\n    } else {\n      setFileList({});\n    }\n  }, [uploaded]);\n  const handleCancel = () => setPreviewOpen(false);\n  const handlePreview = async file => {\n    if (!file.url && !file.preview) {\n      file.preview = await getBase64(file.originFileObj);\n    }\n    setPreviewImage(file.url || file.preview);\n    setPreviewOpen(true);\n    setPreviewTitle(file.name || file.url.substring(file.url.lastIndexOf('/') + 1));\n  };\n  const handleChange = _ref2 => {\n    let {\n      fileList: newFileList\n    } = _ref2;\n    return setFileList(newFileList);\n  };\n  return /*#__PURE__*/_jsxDEV(_Fragment, {\n    children: [/*#__PURE__*/_jsxDEV(Upload, {\n      action: \"https://www.mocky.io/v2/5cc8019d300000980a055e76\",\n      listType: \"picture-card\",\n      fileList: fileList,\n      onPreview: handlePreview,\n      onChange: handleChange\n    }, void 0, false, {\n      fileName: _jsxFileName,\n      lineNumber: 60,\n      columnNumber: 13\n    }, this), /*#__PURE__*/_jsxDEV(Modal, {\n      open: previewOpen,\n      title: previewTitle,\n      footer: null,\n      onCancel: handleCancel,\n      children: /*#__PURE__*/_jsxDEV(\"img\", {\n        alt: \"example\",\n        style: {\n          width: '100%'\n        },\n        src: previewImage\n      }, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 69,\n        columnNumber: 17\n      }, this)\n    }, void 0, false, {\n      fileName: _jsxFileName,\n      lineNumber: 68,\n      columnNumber: 13\n    }, this)]\n  }, void 0, true);\n};\n_s(UploadFiles, \"pRTUWP0OTQsizPOCc64SMNreaFg=\");\n_c = UploadFiles;\nexport default UploadFiles;\nvar _c;\n$RefreshReg$(_c, \"UploadFiles\");","map":{"version":3,"names":["React","Modal","Upload","getBase64","file","Promise","resolve","reject","reader","FileReader","readAsDataURL","onload","result","onerror","error","UploadFiles","uploaded","previewOpen","setPreviewOpen","useState","previewImage","setPreviewImage","previewTitle","setPreviewTitle","fileList","setFileList","useEffect","tempFileList","items","length","map","item","index","uid","id","toString","status","url","link","name","process","env","REACT_APP_BACKEND_URL","split","handleCancel","handlePreview","preview","originFileObj","substring","lastIndexOf","handleChange","newFileList","width"],"sources":["/data/messenger.client/src/components/UploadFiles/index.tsx"],"sourcesContent":["import React from 'react';\nimport { Modal, Upload } from 'antd';\nimport type { RcFile, UploadProps } from 'antd/es/upload';\nimport type { UploadFile } from 'antd/es/upload/interface';\nimport {UploadFilesProps} from \"../../models/props/UploadFilesProps\";\nimport './UploadFiles.scss';\n\nconst getBase64 = (file: RcFile): Promise<string> =>\n    new Promise((resolve, reject) => {\n        const reader = new FileReader();\n        reader.readAsDataURL(file);\n        reader.onload = () => resolve(reader.result as string);\n        reader.onerror = (error) => reject(error);\n    });\n\nconst UploadFiles: React.FC<UploadFilesProps> = ({uploaded}) => {\n    const [previewOpen, setPreviewOpen] = React.useState<boolean>(false);\n    const [previewImage, setPreviewImage] = React.useState('');\n    const [previewTitle, setPreviewTitle] = React.useState('');\n    const [fileList, setFileList] = React.useState<UploadFile[]>();\n\n    React.useEffect(() => {\n        let tempFileList = {} as UploadFile[];\n\n        if (uploaded.items.length > 0) {\n            uploaded.items.map((item, index) => {\n                tempFileList[index] = {\n                    uid: item.id?.toString() || '0',\n                    status: \"done\",\n                    url: item.link,\n                    name: (process.env.REACT_APP_BACKEND_URL + '/' + item.link).split('/')[7]\n                };\n                setFileList({\n                    ...fileList,\n                    ...tempFileList\n                });\n            });\n        } else {\n            setFileList({} as  UploadFile[]);\n        }\n    }, [uploaded]);\n\n    const handleCancel = () => setPreviewOpen(false);\n\n    const handlePreview = async (file: UploadFile) => {\n        if (!file.url && !file.preview) {\n            file.preview = await getBase64(file.originFileObj as RcFile);\n        }\n\n        setPreviewImage(file.url || (file.preview as string));\n        setPreviewOpen(true);\n        setPreviewTitle(file.name || file.url!.substring(file.url!.lastIndexOf('/') + 1));\n    };\n\n    const handleChange: UploadProps['onChange'] = ({ fileList: newFileList }) =>\n        setFileList(newFileList);\n\n    return (\n        <>\n            <Upload\n                action=\"https://www.mocky.io/v2/5cc8019d300000980a055e76\"\n                listType=\"picture-card\"\n                fileList={fileList}\n                onPreview={handlePreview}\n                onChange={handleChange}\n            >\n            </Upload>\n            <Modal open={previewOpen} title={previewTitle} footer={null} onCancel={handleCancel}>\n                <img alt=\"example\" style={{ width: '100%' }} src={previewImage} />\n            </Modal>\n        </>\n    );\n};\n\nexport default UploadFiles;"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,KAAK,EAAEC,MAAM,QAAQ,MAAM;AAIpC,OAAO,oBAAoB;AAAC;AAAA;AAE5B,MAAMC,SAAS,GAAIC,IAAY,IAC3B,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;EAC7B,MAAMC,MAAM,GAAG,IAAIC,UAAU,EAAE;EAC/BD,MAAM,CA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